///////////////////////////////////////////////////////////////////////////////
//-----------------------------------------------------------------------------
#ifndef	__PROFILING_MANAGER_H__
#define	__PROFILING_MANAGER_H__

#include <Config.h>

#ifdef	__MGL_USE_PROFILING_TOOLS__

#include <AbstractManager.h>
#include <Timer.h>
#include <string>
#include <vector>

//-----------------------------------------------------------------------------

#define			PROFILE_OUT		printf

//-----------------------------------------------------------------------------

struct TimeSample
{
	std::string					name;
	f64							startTime;
	f64							endTime;
	f64							diffTime;
	std::vector<TimeSample*>	children;
	TimeSample*					parent;

};

//-----------------------------------------------------------------------------

class	ProfileSample
{
public:
					ProfileSample(std::string name);
					~ProfileSample();

private:
	friend class	ProfilingManager;

	Timer			timer;
	TimeSample*		sample;
	std::string		name;
};

//-----------------------------------------------------------------------------

class ProfilingManager
	:	public AbstractManager<ProfilingManager>
{
public:
					ProfilingManager();
					~ProfilingManager();

	void			ClearTimeSample();
	void			DisplayTimeSample();

private:
	friend class ProfileSample;

	void			StartSample( ProfileSample*	sample );
	void			EndSample( ProfileSample*	sample );
	void			ClearTimeSample( TimeSample*	sample );
	void			DisplayTimeSample( TimeSample*	sample, std::string pre_str );

	TimeSample*		m_rootSample;
	TimeSample*		m_lastSample;
};

#define		MGL_PROFILE(name)				ProfileSample	__sample(name)
#define		MGL_CLEAR_PROFILE_SAMPLE()		ProfilingManager::GetInstance()->ClearTimeSample();
#define		MGL_DISPLAY_PROFILE_SAMPLE()	ProfilingManager::GetInstance()->DisplayTimeSample();

#else	//	__MGL_USE_PROFILING_TOOLS__

#define		MGL_PROFILE(name)
#define		MGL_CLEAR_PROFILE_SAMPLE()
#define		MGL_DISPLAY_PROFILE_SAMPLE()

#endif	//	__MGL_USE_PROFILING_TOOLS__
#endif	//	__PROFILING_MANAGER_H__
//-----------------------------------------------------------------------------
///////////////////////////////////////////////////////////////////////////////
